package com.controller;

import com.dao.impl.LoginDaoImp;
import com.entiy.LogintableEntity;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.dao.*;
import java.util.Map;

public class LoginController extends ActionSupport {
    private LogintableEntity logintableEntity;
    public  LogintableEntity getLogintableEntity(){
        return logintableEntity;
    }
    public void setLogintableEntity(LogintableEntity logintableEntity){
        this.logintableEntity = logintableEntity;
    }

    @Override
    public String execute() throws Exception {
        LoginDao loginDao = new LoginDaoImp();
        LogintableEntity user = loginDao.validateUser(logintableEntity.getlogin(), logintableEntity.getPassword());
        if(user != null){
            Map session=(Map) ActionContext.getContext().getSession();
            session.put("user", user);
            return "success";
        }else{
            return "error";
        }
    }
}
